/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef DEVMON_APP_SCHEMA_H
#define DEVMON_APP_SCHEMA_H

#include <mc/variant.h>
#include <string>
#include <unordered_map>
#include <vector>

namespace devmon {

// 属性信息
struct property_info {
    std::string name;        // 属性名
    std::string type;        // 属性类型
    std::string origin_name; // 原始名称（title）
    std::string interface;   // 接口名
};

// 类信息
struct class_info {
    std::string                                    app;        // 应用名
    std::string                                    name;       // 类名
    std::string                                    path;       // 路径
    std::unordered_map<std::string, property_info> properties; // 属性列表
    std::vector<std::string>                       interfaces; // 接口列表
};

struct class_base_info {
    std::string app;
    std::string path;
};

class app_schema {
public:
    static app_schema& get_instance() {
        static app_schema instance;
        return instance;
    }

    void init(std::unordered_map<std::string, std::string>& app_paths);

    void load(std::vector<std::string> paths);

    class_base_info get_class_info(const std::string& class_name, mc::dict& ctx);
    std::string get_property_intf(const std::string& class_name, const std::string& property_name);
    std::string get_property_type(const std::string& class_name, const std::string& property_name);
    std::string get_property_origin_name(const std::string& class_name,
                                         const std::string& property_name);

private:
    app_schema()  = default;
    ~app_schema() = default;

    void          parse_schema(std::string app, mc::dict& schema);
    std::string   extract_type_from_ref(const std::string& ref);
    property_info parse_property(const std::string& prop_name, const mc::dict& prop_data);

    std::unordered_map<std::string, class_info> m_classes;
};

} // namespace devmon

#endif // DEVMON_APP_SCHEMA_H
